package com.woniu.communitymanagement.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.communitymanagement.entity.Complaint;
import com.woniu.communitymanagement.entity.HttpResult;
import com.woniu.communitymanagement.service.ComplaintService;
import com.woniu.communitymanagement.mapper.ComplaintMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
* @author admin
* @description 针对表【complaint(投诉信息表)】的数据库操作Service实现
* @createDate 2022-11-30 17:38:48
*/
@Service
public class ComplaintServiceImpl extends ServiceImpl<ComplaintMapper, Complaint>
    implements ComplaintService{
    @Autowired(required = false)
    private ComplaintMapper complaintMapper;

    @Override
    public HttpResult selectAll(String typeId,String status,Integer pageIndex,Integer pageSize) {
        List<Complaint> complaints = complaintMapper.selectAll(typeId,status,(pageIndex - 1) * pageSize, pageSize);
        Integer count = complaintMapper.count(typeId,status);
        HttpResult result = null;
        if (complaints!=null && complaints.size()>0){
            result = new HttpResult(complaints,count,200,null);
        } else {
            result = new HttpResult(null,0,500,null);
        }
        return result;
    }

    @Override
    public HttpResult selectByOne(Integer id) {
        Complaint complaint = complaintMapper.selectByOne(id);
        HttpResult result = null;
        if (complaint!=null){
            result = new HttpResult(complaint,0,200,null);
        } else {
            result = new HttpResult(null,0,500,null);
        }
        return result;
    }

    @Override
    public HttpResult insertComplaint(Complaint complaint) {
        int insert = complaintMapper.insert(complaint);
        HttpResult result = null;
        if (insert>0){
            result = new HttpResult(null,0,200,null);
        } else {
            result = new HttpResult(null,0,500,null);
        }
        return result;
    }

    @Override
    public HttpResult deleteComplaint(Integer id) {
        boolean b = removeById(id);
        HttpResult result = null;
        if (b){
            result = new HttpResult(null,0,200,null);
        } else {
            result = new HttpResult(null,0,500,null);
        }
        return result;
    }


    @Override
    public HttpResult updateComplaint(Complaint complaint) {
        boolean b = updateById(complaint);
        HttpResult result = null;
        if (b){
            result = new HttpResult(null,0,200,null);
        } else {
            result = new HttpResult(null,0,500,null);
        }
        return result;
    }

    @Override
    public HttpResult selectAllName() {
        List<Complaint> names = complaintMapper.selectAllName();
        HttpResult result = null;
        if (names!=null && names.size()>0){
            result = new HttpResult(names,0,200,null);
        } else {
            result = new HttpResult(null,0,500,null);
        }
        return result;
    }

    @Override
    public HttpResult selectAllOwner() {
        List<Complaint> owners = complaintMapper.selectAllOwner();
        HttpResult result = null;
        if (owners!=null && owners.size()>0){
            result = new HttpResult(owners,0,200,null);
        } else {
            result = new HttpResult(null,0,500,null);
        }
        return result;
    }


}




